package com.example.cato_cassrndra_.entity;


import com.datastax.oss.driver.api.core.uuid.Uuids;
import lombok.Data;
import org.apache.tinkerpop.shaded.kryo.NotNull;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.rest.core.annotation.RestResource;

import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/*
  分区键决定taco每一行写到那个分区中
  集群键决定行在集群的顺序
  因为@table注解将其映射在一个cassandra实体，所以我们必须新建一个类，定义如何将配料储存到taco列表的ingredients列
 */

@Data
@RestResource(rel = "tacos",path = "tacos")
@Table("tacos")
public class Taco {

    @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED) // 定义分区键
    private UUID id = Uuids.timeBased();

    @NotNull
    @Size(min = 5,message = "name must be ad least 5 characters long")
    private String name;

    @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED,ordering = Ordering.DESCENDING) //定义集群键
    private Date createAt = new Date();

    @Size(min = 1 ,message = "You must choose at least 1 ingredient")
    @Column("ingredients")     // 将列表映射到ingredients列中
    private List<IngredientUDT> ingredients;

}
